<?php
namespace Forum\Controller;
use Think\Controller;
class UsersController extends CommonController {
    public function index(){
    }
    
    /*
     * 用户列表
     */
    public function lists() {
        
        if(IS_POST)
        {
            $DB = M("forum_users");
            $create_num = I("post.create_num");
            
            for($i=0;$i<$create_num;$i++)
            {
                $dataList[] = array('mid'=>0,'nickname'=>  $this->random_number(),'ctime'=>I('server.REQUEST_TIME'),'utime'=>I('server.REQUEST_TIME'),'isprivate'=>1);
            }
            $DB->addAll($dataList);
            
            $this->success("生成成功");
            
            
        }
        else
        {
            $DB = M("forum_users");

   //        $map
            $res = $DB->where($map)->select();

            $this->assign("results", $res);

            $this->display();
        }
        
    }
    
    
    /*
     * 用户详情+修改
     */
    public function modify() {
        
        if(IS_POST)
        {
            $DB = M("forum_users");
            $userid = I("post.userid");
            $DB->userid = $userid;
            /*
             * 修改的功能
             */
            if(!empty($_FILES['avatar']['tmp_name']))
            {
                $upload = new \Think\Upload();// 实例化上传类
                $upload->maxSize   =     31457280 ;// 设置附件上传大小
                $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
                $upload->rootPath  =      'Public/'; // 设置附件上传目录
                $upload->savePath  =      '/uploads/'; // 设置附件上传目录
                
                // 上传文件 
                $info   =   $upload->uploadOne($_FILES['avatar']);
                
                if(!$info) {// 上传错误提示错误信息
                    $this->error($upload->getError());
                } 
                
                $DB->avatar="/".$upload->rootPath.$info['savepath'].$info['savename']; 
                
            }
            $isban = I("post.isban");
            if($isban==1)
            {
                $DB->banexpired_time = I("server.REQUEST_TIME")+3600*24;
            }
            else
            {
               $DB->banexpired_time=0; 
            }
            $DB->isban = $isban;
            $DB->invisible = I("post.invisible");
            
            
            if($DB->save())
            {
                $this->success("修改成功");
            }
            else
            {
                print_r($DB->getLastSql());
//                $this->error("操作失败");
            }
        }
        else
        {
            $userid = I("get.userid");
            $DB = M("forum_users");
            $res = $DB->find($userid);

            $this->assign("result", $res);

            $this->display();
        }
        
        
    }
}